//
//  TLST_discountCell.m
//  Travel_World
//
//  Created by lanou on 15/10/17.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "TLST_discountCell.h"
#import "SSCollectionModel.h"

@implementation TLST_discountCell
+ (instancetype)discountCellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"dicCell";
    TLST_discountCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[TLST_discountCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.picImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.picImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.numberOfLines = 0;
        [self.contentView addSubview:self.titleLabel];
        
        self.priceLabel = [[UILabel alloc] init];
        self.priceLabel.font = [UIFont systemFontOfSize:15];
        self.priceLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.priceLabel];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.picImageView.frame = CGRectMake(10, 10, 100*WID, 80);
    self.titleLabel.frame = CGRectMake(100*WID+20, 2, (WIDTH-130)*WID, 60);
    self.priceLabel.frame = CGRectMake(100*WID+20, 60, (WIDTH-130)*WID, 30);
}
- (void)setDataModel:(id)dataModel
{
    if ([dataModel isKindOfClass:[SSCollectionModel class]]) {
        SSCollectionModel *disModel = dataModel;
        [self.picImageView sd_setImageWithURL:[NSURL URLWithString:disModel.pic] placeholderImage:[UIImage imageNamed:@"placeholder1"]];
        
        self.titleLabel.text = disModel.title;
        
        NSString *priceStr = disModel.price;
        NSString *price = [priceStr substringWithRange:NSMakeRange(4, priceStr.length-11)];
        self.priceLabel.text = [NSString stringWithFormat:@"%@元起",price];
    } else {
        TLS_countryModel *couModel = dataModel;
        [self.picImageView sd_setImageWithURL:[NSURL URLWithString:couModel.photo] placeholderImage:[UIImage imageNamed:@"placeholder1"]];
        self.titleLabel.text = couModel.cnname;
        self.priceLabel.text = couModel.enname;
    }
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
